package top.songxs.handler;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import top.songxs.result.Result;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//自定义全局异常 处理
@ControllerAdvice
public class MyExceptionHandler {

    @ResponseBody
    @ExceptionHandler( Exception.class)
    public Result handlerException(Exception e){
        System.out.println(e.getMessage());
        return Result.fail(e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public String runTimExceptionHandler(HttpServletRequest request, HttpServletResponse response,
                                         RuntimeException e){


        return "/common/failPage";
    }
}
